// pages/school/detail/index.js
import {SchoolModel} from "../../../models/school/SchoolModel";

const schoolModel = new SchoolModel()
Page({

    /**
     * 页面的初始数据
     */
    data: {

        schoolDetail: [],
        teacherList: [],
        sId: '',
        current: 1,
        pageSize: 10

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

        let sId = options.sId
        this.data.sId = sId
        this._init(sId,this.data.current,this.data.pageSize)

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },
    _init(sId, current, pageSize) {

        const getDetail = schoolModel.getSchoolDetail(sId)
        const getSchoolTeacher = schoolModel.getSchoolTeacher(sId, current, pageSize)
        Promise.all([getDetail,getSchoolTeacher])
            .then(res => {
                this.setData({
                    schoolDetail: res[0],
                    teacherList: res[1]
                })
            })
            .catch(err => {
                console.log(err);
            })
    },

    callPhone(){

        wx.makePhoneCall({
          phoneNumber: this.data.schoolDetail.s_contact_phone //仅为示例，并非真实的电话号码
        })

    }
})